package com.sjl.estest.controller;

import cn.easyes.core.biz.EsPageInfo;
import cn.easyes.core.core.EsWrappers;
import cn.hutool.core.util.StrUtil;
import com.sjl.estest.domain.index.HotelIndex;
import com.sjl.estest.esmapper.EsHotelMapper;
import com.sjl.estest.service.IHotelService;
import lombok.RequiredArgsConstructor;
import org.elasticsearch.client.core.PageParams;
import org.elasticsearch.index.query.Operator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/hotel")
@RequiredArgsConstructor
public class HotelController {

    private final IHotelService iHotelService;

    private final EsHotelMapper esHotelMapper;

    @GetMapping("/listIndexAll")
    @SuppressWarnings("unchecked")
    public EsPageInfo<HotelIndex> listIndexAll(String key, PageParams pageParams) {


        return EsWrappers.lambdaChainQuery(esHotelMapper)
                .multiMatchQuery(StrUtil.isNotBlank(key),key, Operator.OR, 0, 0F,
                        HotelIndex::getBrand, HotelIndex::getName, HotelIndex::getAddress)
                .page(pageParams.getFrom(), pageParams.getSize());
    }



}
